package com.example.test;

import com.tencent.weibo.sdk.android.model.GlobalVar;
import android.app.Activity;
import android.app.ActivityGroup;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Window;
import android.widget.TabHost;

public class MainTabActivity extends ActivityGroup {

	Intent [] intents;
	Class<?> [] arrClasses={
	          FriLineActivity.class,
	          MsgTabActivity.class,
	          HomeActivity.class,
	          PubFriLineActivity.class,
	          MoreActivity.class
	          };
	int [] arrDrawableID ={R.drawable.ic_com_sina_weibo_sdk_logo,R.drawable.ic_com_sina_weibo_sdk_logo,R.drawable.ic_com_sina_weibo_sdk_logo,R.drawable.ic_com_sina_weibo_sdk_logo,R.drawable.ic_com_sina_weibo_sdk_logo};
    int [] arrLables = {R.string.home,R.string.msg,R.string.me,R.string.square,R.string.more };
      
    Bundle [] arrBundle =new Bundle[ arrClasses.length];
    
	TabHost tabHost;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
	
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);  
		setContentView(R.layout.main_tab);
		tabHost =(TabHost)findViewById(android.R.id.tabhost);
		tabHost.setup();
		tabHost.setup(this.getLocalActivityManager());  
		tabHost.bringToFront();
		Bundle bundle = getIntent().getExtras();
        addSpec();
        
	}
	public void initBuddles()
	{
		for(int i=0;i<arrBundle.length; i++)
		{
			arrBundle[i]=new Bundle();
		}
		arrBundle[0].putString("activity_type", "FriTimeline");
		arrBundle[2].putString("activity_type", "home");
	}
    public void initIntent()
    {
    	initBuddles();
    	intents =new Intent[arrClasses.length];
    	for (int i=0;i<intents.length;i++) {
			intents[i]=new Intent();
		}
    	int i=0;
    	for (Class<?> myclass : arrClasses) {
    		intents[i].putExtras(arrBundle[i]);
			intents[i].setClass(this, myclass);
			i++;
		}
    }
    public void addSpec()
    {
    	initIntent();
    	int count = intents.length;
    	int i =0;
    	for (Intent intent : intents) {
    		tabHost.setCurrentTab(i);
			tabHost.addTab(buildTagSpec(i+"",arrLables[i],arrDrawableID[i], intent));
		    i++;
    	}
    }
    private TabHost.TabSpec buildTagSpec(String tagName, int tagLable,
    		 
            int icon, Intent content) {
  
        return tabHost.newTabSpec(tagName)
  
               .setIndicator(getResources().getString(tagLable),
  
                      getResources().getDrawable(icon)).setContent(content);
  
     }
    }


